package com.example.second_home_work

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    val expert = ProgramExpert()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val button = findViewById<Button>(R.id.button)
        button.setOnClickListener {
            val spinner = findViewById<Spinner>(R.id.spinner)
            val selectedFeature = spinner.selectedItem.toString()
            val textView = findViewById<TextView>(R.id.textView)
            textView.text = expert.getLanguage(selectedFeature)

            // 动态添加TextView
            addTextViews()
        }
    }

    private fun addTextViews() {
        val linearLayout = findViewById<LinearLayout>(R.id.linear_layout)

        for (i in 0..50) { // 例如添加11个TextView
            val textView = TextView(this)
            val spinner = findViewById<Spinner>(R.id.spinner)
            val selectedFeature = spinner.selectedItem.toString()
            textView.text = expert.getLanguage(selectedFeature)
            textView.layoutParams = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
            linearLayout.addView(textView)
        }
    }
}